package com.xinongbest.mall.controller;

import com.github.pagehelper.PageInfo;
import com.xinongbest.mall.common.ApiRestResponse;
import com.xinongbest.mall.model.dto.ProductRequestDto;
import com.xinongbest.mall.model.pojo.Product;
import com.xinongbest.mall.service.ProductService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductService productService;

    @ApiOperation("前台-商品详情接口")
    @PostMapping("/detail")
    public ApiRestResponse<Product> detail(Integer id) {
        return ApiRestResponse.success(productService.detail(id));
    }

    @PostMapping("/list")
    public ApiRestResponse<PageInfo> list(ProductRequestDto requestDto) {
        return ApiRestResponse.success(productService.selectList(requestDto));
    }

    @GetMapping("/category")
    public ApiRestResponse<List<String>> categoryList() {
        List<String> category = Arrays.asList("首页", "居家", "美食", "服饰", "数码", "生鲜", "家装", "玩具", "城市");
        return ApiRestResponse.success(category);
    }
}
